package com.wang.gulimall.order.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rabbitmq.client.Channel;
import com.wang.common.utils.PageUtils;
import com.wang.common.utils.Query;
import com.wang.gulimall.order.dao.OrderItemDao;
import com.wang.gulimall.order.entity.OrderItemEntity;
import com.wang.gulimall.order.entity.OrderReturnReasonEntity;
import com.wang.gulimall.order.service.OrderItemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.Map;

//@RabbitListener(queues = {"hello-java-queue"})
@Service("orderItemService")
@Slf4j
public class OrderItemServiceImpl extends ServiceImpl<OrderItemDao, OrderItemEntity> implements OrderItemService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<OrderItemEntity> page = this.page(
                new Query<OrderItemEntity>().getPage(params),
                new QueryWrapper<OrderItemEntity>()
        );

        return new PageUtils(page);
    }

    //测试消费者消费消息 考点 如何在消费者端保障消息的可靠性
    //@RabbitHandler
    @RabbitListener(queues = {"hello-java-queue"})
    public void receiveMessage(Message message, OrderReturnReasonEntity content, Channel channel) throws IOException {
        log.info("收到消息");
        byte[] body = message.getBody();
        //通道内自增的数字
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        log.info("消息内容{}" + body);
        channel.basicAck(deliveryTag, false);
    }

}